//
//  BaseViewController.swift
//  微博Swift
//
//  Created by apple on 15/9/22.
//  Copyright © 2015年 cc. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    // 判断是否登录
    var isUserLogin = false
    // 访客视图
    var visitorView: VisitorViewController?
    
    override func loadView() { // 选择显示视图

        isUserLogin ? super.loadView() : setViewControllers()
    }
    
    // 设置访客视图
    private func setViewControllers() {
        visitorView = VisitorViewController()
        
        visitorView?.loginBtn.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.registBtn.addTarget(self, action: "visitorViewDidRegist", forControlEvents: UIControlEvents.TouchUpInside)
        
        view = visitorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidRegist")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidLogin")
    }
    
    // mark: - 代理方法
    func visitorViewDidLogin() {
        
        let vc = OauthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
        
        print("触发代理Login")
    }
    
    func visitorViewDidRegist() {
        print("触发代理Regist")
    }
}
